﻿Public Class Detapa

    Public Shared Function SeleccionarTodo(ByVal descEmpresa As String) As List(Of Eetapa)
        Dim etapas As List(Of Eetapa) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_etapa_sel", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            etapas = New List(Of Eetapa)
                            Dim etapa As Eetapa = Nothing
                            Do While dr.Read
                                etapa = New Eetapa( _
                                    dr.GetInt32(dr.GetOrdinal("idProyecto")), _
                                    dr.GetString(dr.GetOrdinal("descProyecto")), _
                                    dr.GetInt32(dr.GetOrdinal("idEtapa")), _
                                    dr.GetString(dr.GetOrdinal("descEtapa")), _
                                    dr.GetDecimal(dr.GetOrdinal("areaTerreno")), _
                                    dr.GetInt32(dr.GetOrdinal("nroInmuebles")), _
                                    dr.GetString(dr.GetOrdinal("fchInicio")), _
                                    dr.GetString(dr.GetOrdinal("fchFin")), _
                                    dr.GetString(dr.GetOrdinal("email")), _
                                    dr.GetString(dr.GetOrdinal("fchCreacion")), _
                                    dr.GetString(dr.GetOrdinal("fchModificacion")), _
                                    dr.GetString(dr.GetOrdinal("observacion")), _
                                    dr.GetInt32(dr.GetOrdinal("idEntidadFin")), _
                                    dr.GetString(dr.GetOrdinal("descEntidadFin")), _
                                    dr.GetString(dr.GetOrdinal("estado")), _
                                    dr.GetString(dr.GetOrdinal("idUbigeo")), _
                                    dr.GetString(dr.GetOrdinal("departamento")), _
                                    dr.GetString(dr.GetOrdinal("provincia")), _
                                    dr.GetString(dr.GetOrdinal("distrito")))
                                etapas.Add(etapa)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return etapas
    End Function
    Public Shared Function SeleccionarTodo(ByVal descEmpresa As String, ByVal idProyecto As Int32) As List(Of Eetapa)
        Dim etapas As List(Of Eetapa) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_etapa_selXProyecto", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idProyecto", SqlDbType.Int).Value = idProyecto
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            etapas = New List(Of Eetapa)
                            Dim etapa As Eetapa = Nothing
                            Do While dr.Read
                                etapa = New Eetapa( _
                                    dr.GetInt32(dr.GetOrdinal("idProyecto")), _
                                    dr.GetString(dr.GetOrdinal("descProyecto")), _
                                    dr.GetInt32(dr.GetOrdinal("idEtapa")), _
                                    dr.GetString(dr.GetOrdinal("descEtapa")), _
                                    dr.GetDecimal(dr.GetOrdinal("areaTerreno")), _
                                    dr.GetInt32(dr.GetOrdinal("nroInmuebles")), _
                                    dr.GetString(dr.GetOrdinal("fchInicio")), _
                                    dr.GetString(dr.GetOrdinal("fchFin")), _
                                    dr.GetString(dr.GetOrdinal("email")), _
                                    dr.GetString(dr.GetOrdinal("fchCreacion")), _
                                    dr.GetString(dr.GetOrdinal("fchModificacion")), _
                                    dr.GetString(dr.GetOrdinal("observacion")), _
                                    dr.GetInt32(dr.GetOrdinal("idEntidadFin")), _
                                    dr.GetString(dr.GetOrdinal("descEntidadFin")), _
                                    dr.GetString(dr.GetOrdinal("estado")), _
                                    dr.GetString(dr.GetOrdinal("idUbigeo")), _
                                    dr.GetString(dr.GetOrdinal("departamento")), _
                                    dr.GetString(dr.GetOrdinal("provincia")), _
                                    dr.GetString(dr.GetOrdinal("distrito")))
                                etapas.Add(etapa)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return etapas
    End Function
    Public Shared Function SeleccionarTodoXetapa(ByVal descEmpresa As String, ByVal eetapa As Eetapa) As List(Of Eetapa)
        Dim etapas As List(Of Eetapa) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_etapa_selXProyectoEtapa", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idProyecto", SqlDbType.Int).Value = eetapa.idProyecto
                cmd.Parameters.Add("@idEtapa", SqlDbType.Int).Value = eetapa.idEtapa
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            etapas = New List(Of Eetapa)
                            Dim etapa As Eetapa = Nothing
                            Do While dr.Read
                                etapa = New Eetapa( _
                                    dr.GetInt32(dr.GetOrdinal("idProyecto")), _
                                    dr.GetString(dr.GetOrdinal("descProyecto")), _
                                    dr.GetInt32(dr.GetOrdinal("idEtapa")), _
                                    dr.GetString(dr.GetOrdinal("descEtapa")), _
                                    dr.GetDecimal(dr.GetOrdinal("areaTerreno")), _
                                    dr.GetInt32(dr.GetOrdinal("nroInmuebles")), _
                                    dr.GetString(dr.GetOrdinal("fchInicio")), _
                                    dr.GetString(dr.GetOrdinal("fchFin")), _
                                    dr.GetString(dr.GetOrdinal("email")), _
                                    dr.GetString(dr.GetOrdinal("fchCreacion")), _
                                    dr.GetString(dr.GetOrdinal("fchModificacion")), _
                                    dr.GetString(dr.GetOrdinal("observacion")), _
                                    dr.GetInt32(dr.GetOrdinal("idEntidadFin")), _
                                    dr.GetString(dr.GetOrdinal("descEntidadFin")), _
                                    dr.GetString(dr.GetOrdinal("estado")), _
                                    dr.GetString(dr.GetOrdinal("idUbigeo")), _
                                    dr.GetString(dr.GetOrdinal("departamento")), _
                                    dr.GetString(dr.GetOrdinal("provincia")), _
                                    dr.GetString(dr.GetOrdinal("distrito")))
                                etapas.Add(etapa)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return etapas
    End Function

End Class
